package com.huoyun.channel.action;

import java.util.List;

import com.huoyun.base.action.BaseAction;
import com.huoyun.base.bean.Page;
import com.huoyun.base.dao.evt.DaoBaseEvt;
import com.huoyun.cargo.bean.CargoItem;
import com.huoyun.cargo.service.CargoService;
import com.huoyun.cargo.service.evt.SelectCargosForCarEvt;

public class GoodsChannelAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	/**
	 * 频道标示
	 */
	private String menu = "goodsChannel";
	/**
	 * 搜索条件
	 */
	private SelectCargosForCarEvt searchEvt;
	/**
	 * 搜索结果：详细货物列表
	 */
	private List<CargoItem> cargoItemList;
	/**
	 * 管理cargo的service
	 */
	private CargoService cargoService;
	/**
	 * 起始地
	 */
	private String startArea;
	/**
	 * 目的地
	 */
	private String destinationArea;
	/**
	 * 搜索出的一页货源信息
	 */
	private Page cargoItemPage;
	
	/**
	 * 点击导航栏，跳转到“货源搜索”
	 * @return
	 * @author ChengXin
	 */
	public String preSearch()
	{
		try
		{
			DaoBaseEvt evt = new DaoBaseEvt();
			evt.setPageNo(pageNo);
			evt.setPageCount(PAGE_COUNT);
			
			cargoItemPage = cargoService.getAllCargoItem(evt);
		}
		catch (Exception e)
		{
			return ERROR;
		}
		return SUCCESS;
	}
	
	/**
	 * 搜索货源列表
	 * @return
	 * @author ChengXin
	 */
	public String searchGoods()
	{
		if (startArea != null && !startArea.equals("") && destinationArea != null && !destinationArea.equals(""))
		{
			searchEvt = new SelectCargosForCarEvt();
			String[] startAreaArray = startArea.split("-");
			String[] destinationAreaArray = destinationArea.split("-");
			
			if (startAreaArray.length == 3 && destinationAreaArray.length == 3)
			{
				searchEvt.setStartProvince(startAreaArray[0]);
				searchEvt.setStartCity(startAreaArray[1]);
				searchEvt.setStartTown(startAreaArray[2]);
				
				searchEvt.setDestinationProvince(destinationAreaArray[0]);
				searchEvt.setDestinationCity(destinationAreaArray[1]);
				searchEvt.setDestinationTown(destinationAreaArray[2]);
				
				searchEvt.setPageNo(pageNo);
				searchEvt.setPageCount(PAGE_COUNT);
				
				cargoItemPage = cargoService.selectCargosForCar(searchEvt);
				
				return SUCCESS;
			}
			else
			{
				return ERROR;
			}
		}
		else
		{
			return ERROR;
		}
	}
	

	public String getMenu() {
		return menu;
	}
	public SelectCargosForCarEvt getSearchEvt() {
		return searchEvt;
	}
	public void setSearchEvt(SelectCargosForCarEvt searchEvt) {
		this.searchEvt = searchEvt;
	}
	public List<CargoItem> getCargoItemList() {
		return cargoItemList;
	}
	public void setCargoItemList(List<CargoItem> cargoItemList) {
		this.cargoItemList = cargoItemList;
	}
	public CargoService getCargoService() {
		return cargoService;
	}
	public void setCargoService(CargoService cargoService) {
		this.cargoService = cargoService;
	}

	public String getStartArea() {
		return startArea;
	}

	public void setStartArea(String startArea) {
		this.startArea = startArea;
	}

	public String getDestinationArea() {
		return destinationArea;
	}

	public void setDestinationArea(String destinationArea) {
		this.destinationArea = destinationArea;
	}

	public Page getCargoItemPage() {
		return cargoItemPage;
	}

	public void setCargoItemPage(Page cargoItemPage) {
		this.cargoItemPage = cargoItemPage;
	}
}
